<template>
  <div>
    <el-table v-loading="table.loading" :data="table.data" border>
      <el-table-column prop="name" label="名称" />
      <el-table-column prop="created_at" label="创建时间" />
      <el-table-column label="操作">
        <template slot-scope="t">
          <el-button type="primary" @click="handleEdit(t.row)">编辑</el-button>
          <el-button type="danger" @click="handleDelete(t.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <WrapPagination>
      <el-pagination
        class="pagination"
        :current-page="table.page"
        :page-sizes="$store.state.app.pagination.sizes"
        :page-size="table.size"
        :layout="$store.state.app.pagination.layout"
        :total="table.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </WrapPagination>
  </div>
</template>

<script>
import { TableMixin } from '../../../components/mixin'
import { del, getList } from '../../../api/role'

export default {
  mixins: [TableMixin],
  mounted() {
    this.getList()
  },
  methods: {
    getList() {
      this.wrapResourceList(getList, {})
    },
    handleEdit(row) {
      this.$router.push({
        name: 'role-edit',
        params: {
          id: row.id
        }
      })
    },
    handleDelete(row) {
      this.$confirm('此操作可能引发系统故障，请确认您了解您正在进行操作的危险性, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        del(row.id).then(() => {
          this.getList()
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
